package org.ax.service.device.imple;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.ax.mapper.device.DeviceMaintainMapper;
import org.ax.pojo.device.DeviceFault;
import org.ax.pojo.device.DeviceMaintain;
import org.ax.service.device.DeviceMaintainService;
import org.ax.service.employ.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 编程人:赵浩鑫
 * 时间:2021-03-03-15:19
 */
@Service
public class IDeviceMaintainService extends ServiceImpl<DeviceMaintainMapper, DeviceMaintain> implements DeviceMaintainService {
    @Autowired
    EmployeeService employeeService;
    @Override
    public Page<DeviceMaintain> searchDeviceMaintains(Page page, String empId) {
        QueryWrapper<DeviceMaintain> queryWrapper=new QueryWrapper<DeviceMaintain>();
        queryWrapper.eq(!StringUtils.isBlank(empId), "device_Maintain_Emp_Id",empId);
        Page page1 = getBaseMapper().selectPage(page, queryWrapper);
        List<DeviceMaintain> deviceMaintains=(List<DeviceMaintain>)page.getRecords();
        for (DeviceMaintain deviceMaintain : deviceMaintains) {
            deviceMaintain.setEmployee(employeeService.toEmployeeId(deviceMaintain.getDeviceMaintainEmpId()));
        }
        page1.setRecords(deviceMaintains);
        return page1;
    }

    @Override
    public boolean addDeviceMaintain(DeviceMaintain deviceMaintain) {
        return getBaseMapper().insert(deviceMaintain)>0;
    }

    @Override
    public boolean updateDeviceMaintain(DeviceMaintain deviceMaintain) {
        return getBaseMapper().updateById(deviceMaintain)>0;
    }

    @Override
    public boolean deletesDeviceMaintain(String[] ids) {
        return getBaseMapper().deleteBatchIds(Arrays.asList(ids))>0;
    }

    @Override
    public DeviceMaintain toDeviceMaintainId(String id) {
        return getBaseMapper().selectById(id);
    }

    @Override
    public List<DeviceMaintain> findDeviceMaintains() {
        return getBaseMapper().selectList(null);
    }
}
